package com.lechuang.goods.controller;

import com.lechuang.common.result.Result;
import com.lechuang.goods.dto.GoodsCategoryListDTO;
import com.lechuang.goods.dto.GoodsCategorySaveDTO;
import com.lechuang.goods.manager.GoodsCategoryManager;
import com.lechuang.goods.vo.GoodsCategoryDetailVO;
import com.lechuang.goods.vo.GoodsCategoryListVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/category")
@Tag(name = "商品分类")
public class GoodsCategoryController {

    @Resource
    private GoodsCategoryManager goodsCategoryManager;

    @PostMapping("/list")
    @Operation(summary = "商品分类-列表")
    public Result<List<GoodsCategoryListVO>> list(@RequestBody GoodsCategoryListDTO goodsCategoryListDTO){
        List<GoodsCategoryListVO> list = goodsCategoryManager.list(goodsCategoryListDTO);
        return Result.success(list);
    }

    @PostMapping("/saveOrUpdate")
    @Operation(summary = "商品分类-新增、修改")
    public Result<Object> saveOrUpdate(@RequestBody GoodsCategorySaveDTO goodsCategorySaveDTO){
        goodsCategoryManager.saveOrUpdate(goodsCategorySaveDTO);
        return Result.success();
    }

    @PostMapping("/delete")
    @Operation(summary = "商品分类-删除")
    public Result<Object> delete(@Schema(description = "商品分类主键id") @RequestParam Long id){
        goodsCategoryManager.delete(id);
        return Result.success();
    }

    @PostMapping("/detail")
    @Operation(summary = "商品分类-详情")
    public Result<GoodsCategoryDetailVO> detail(@Schema(description = "商品分类主键id")@RequestParam Long id){
        GoodsCategoryDetailVO detailVO = goodsCategoryManager.detail(id);
        return Result.success(detailVO);
    }
}
